<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
        0.补充,数组填充
     */

    // 0.1 第一种
    console.log(Array(5).fill(null).map((item, index) => index + 1))
    // 0.2 第二种
    console.log(Array.from({length: 5}).map((_, index) => index + 1))

    /*
        1.叔叔要加速了
     */
    async function randomDelay(id) {
        const delay = 1000 || Math.floor(Math.random() * 1000);
        return new Promise(resolve => setTimeout(() => {
            console.log(`${id} wait ${delay}ms and finished`)
            resolve(id)
        }, delay))
    }

    async function foo() {
        const start = Date.now();
        const promise = Array(5).fill(null).map((_, i) => randomDelay(i))
        for (const p of promise) {
            console.log(`awaited ${await p}`)
        }
        console.log(`${Date.now() - start}ms elapsed`)
    }

    foo();
</script>
</body>
</html>